from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_jwt_extended import JWTManager
from flask_cors import CORS
from config import Config

# 初始化扩展
db = SQLAlchemy()
migrate = Migrate()
jwt = JWTManager()
cors = CORS()

def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)
    
    # 初始化扩展
    db.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)
    cors.init_app(app)
    
    # 注册蓝图
    from app.routes import auth, user, vital_signs, body_composition, blood_test, daily_activity, health_assessment
    
    app.register_blueprint(auth.bp)
    app.register_blueprint(user.bp)
    app.register_blueprint(vital_signs.bp)
    app.register_blueprint(body_composition.bp)
    app.register_blueprint(blood_test.bp)
    app.register_blueprint(daily_activity.bp)
    app.register_blueprint(health_assessment.bp)
    
    return app